package com.itheima.ticket.mai3;

public class Ticket implements Runnable {
    private static int count = 100;

    @Override
    public void run() {
        //完成卖票操作
        while (true) {
            if (count > 0) {
                Ticket.mai();
            } else {
                break;
            }
        }
    }

    public static synchronized void mai() {//有锁对象   谁是锁对象?  //this //如果是静态方法  锁对象是 类.class
        //类的字节码对象
        //类名  对象名 =值;
       //Class ticketClass = Ticket.class;
        String name = Thread.currentThread().getName();
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (count > 0) {
            count--;
            System.out.println(name + "卖了一张还剩" + count + "张票");
        } else {
            return;
        }
    }
}
